//
//  FriendVC.m
//  TestAll
//
//  Created by wen on 2020/8/4.
//  Copyright © 2020 ZDHS. All rights reserved.
//

#import "FriendVC.h"
#import "Masonry.h"
#import "ChatVC.h"
#import <HYBNetworking.h>

@interface FriendVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *mainTableview;
@property(nonatomic,strong)NSMutableArray *arrData;
@end

@implementation FriendVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithTitle:@"创建" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightAction)];
    
    self.arrData = NSMutableArray.array;
    for (int i=1; i<12; i++) {
        [self.arrData addObject:[NSString stringWithFormat:@"%d",i]];
    }
    [self _initTablieView];
}
-(void)_initTablieView{
    
    
    self.edgesForExtendedLayout = UIRectEdgeNone; // 不偏移 64
    self.mainTableview  = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:(UITableViewStylePlain)];
//    _mainTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.mainTableview.backgroundColor = [UIColor colorWithRed:(239)/255.0 green:(239)/255.0 blue:(244)/255.0 alpha:(1)];
//    self.mainTableview.rowHeight = 65;
    _mainTableview.delegate = self;
    _mainTableview.dataSource =  self;
    [self.view addSubview:_mainTableview];
    [_mainTableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.view);
    }];
    
    [self.mainTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_0_0_0_0"];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_0_0_0_0" forIndexPath:indexPath];
    cell.backgroundColor = UIColor.clearColor;
    
    if (indexPath.row<10) {
        cell.textLabel.text = [NSString stringWithFormat:@"用户%@",_arrData[indexPath.row]];
    }else{
        cell.textLabel.text = @"群组测试";
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ChatVC *chat;
    if (indexPath.row<10) {
        chat = [[ChatVC alloc] initWithConversationType:ConversationType_PRIVATE
        targetId:_arrData[indexPath.row]];
    }else{
        chat = [[ChatVC alloc] initWithConversationType:ConversationType_GROUP
                                               targetId:@"100"];
    }
    
    chat.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:chat animated:YES];
}

-(void)rightAction{
    
    NSString *url = @"http://hongqi.wengegroup.com:9115/api/group/createGroup";
    NSDictionary *dic = @{@"groupId":@"100",@"groupName":@"群组测试",@"groupUserIds":@"1,2,3,4,5,6,7,8,9,10"};
    
    [HYBNetworking configRequestType:(kHYBRequestTypeJSON) responseType:(kHYBResponseTypeJSON) shouldAutoEncodeUrl:NO callbackOnCancelRequest:NO];
    [HYBNetworking postWithUrl:url refreshCache:NO params:dic success:^(id response) {
        NSLog(@"");
        
    } fail:^(NSError *error) {
        NSLog(@"");
    }];
}
@end
